<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\console\command\optimize\Schema;
use think\Db;

/**
 * 流程
 */
class Moban extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];

    public function getalllist(){

        $user=$this->auth->getUser();

        $list=Db::name('moban')->order('time desc')->select();

        $time=strtotime('-3 day');

        foreach ($list as &$key){
            $key['new']=0;
            if ($key['time']>$time){

                $key['new']=1;
                $key['name']=date('m-d',$key['time']).$key['name'];

            }

            $logc['user_id']=$user['id'];
            $logc['find']='moban'.$key['id'];

            $see=Db::name('see_log')->where($logc)->find();

            $key['look']=0;
            if ($see){
                $key['look']=1;
            }

        }

        $this->success('moban',$list);

    }

    /**
     * 查看模版
     */
    public function seemobanbyid(){
        $user=$this->auth->getUser();

        $id=$this->request->param('id');

        $list=Db::name('moban')->where(['id'=>$id])->find();

        $logc['user_id']=$user['id'];
        $logc['find']='moban'.$id;
        $logc['desc']=$user['nickname'].'完成了'.$list['name'];
        $logc['time']=time();


        Db::name('see_log')->data($logc)->insert();

        $this->success('操作成功！');

    }
    /**
     *  查看全部模版
     */
    public function seemoban(){

        $list=Db::name('moban')->select();

        $user=$this->auth->getUser();

        foreach ($list as $key){

            $logc['user_id']=$user['id'];
            $logc['find']='moban'.$key['id'];

            $find=Db::name('see_log')->where($logc)->find();

            if (!$find){

                $logc['desc']=$user['nickname'].'完成了'.$key['name'];
                $logc['time']=time();
                Db::name('see_log')->data($logc)->insert();
            }
        }
        $this->success('操作成功！');



    }
    /**
     * 模版信息
     */
    public function getinfobyid(){

        $user=$this->auth->getUser();
        $id=$this->request->param('id');

        $find=Db::name('moban')->where(['id'=>$id])->find();

        $find['v_link']=cdnurl($find['file'],true);

        $this->success('操作成功',$find);

    }

}